package org.bookie.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.AccessType;

/**
 * Class modelling a betting group. Every group exists of several {@link User}s.
 * Every {@link User} can participate in several groups.
 * 
 * @author Igor Drobiazko
 *
 */
@Entity
@AccessType("field")
@Table(name="Groups")
public class Group extends CommonEntity {
	private static final long serialVersionUID = 1L;
	
	/**Unique name of the group*/
	@Column(nullable = false, unique = true)
	private String name;
	
	/**Description of the group*/
	@Column
	private String description;
	
	/**Number of group members*/
	@Transient private int userCount;
	
	/**
	 * List of {@link User}s participating in the group
	 */
	@ManyToMany(targetEntity=User.class,mappedBy="groups")
	private List<User> users = new ArrayList<User>();
	
	/**Default constructor*/
	public Group(){super();}
	/**
	 * Constructs a group by a specified name.
	 * @param name name of the group
	 */
	public Group(String name) {
		setName(name);
	}
	
	/**
	 * Get the unique name of the group
	 * @return string representing the name of the group
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Set the unique name of the group
	 * @param name name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Get the {@link User}s participating in the group
	 * @return List of User
	 */
	public List<User> getUsers() {
		return users;
	}
	/**
	 * Get the number of group members
	 */
	public int getUserCount() {
		return userCount;
	}
	
	/**
	 * Set the number of group members
	 * @param userCount number to set
	 */
	public void setUserCount(int userCount) {
		this.userCount = userCount;
	}
	
	/**
	 * Get the group description
	 */
	public String getDescription() {
		return description;
	}
	
	/**
	 * Get the group description
	 * @param description description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
